<script>
import outMain from "@/components/outMain.vue";
import talkForm from "@/views/modules/talkForm.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { connectRecord, connectRecordSave } from "@/http/api";
export default {
  components: { outMain, talkForm },
  name: "",
  data() {
    return {
      showTalk: false,
      tableData: [],
      statusArr: [],
      queryData: {
        real_name: "",
        connect_remark: "",
        connect_label: "",
        staff_name: "",
        page: 1,
        per_page: 20,
      },
      total: 0,
      maskItem: {},
    };
  },
  props: {},
  setup() {},
  methods: {
    detailFn(id) {
      this.$router.push({
        path: "/salaPublicDetail",
        query: { id: id, page: this.queryData.page },
      });
    },
    async comfirFn(formData) {
      const { data } = await connectRecordSave(formData);
      if (data.code == 1) {
        ElMessage({
          type: "success",
          message: "操作成功",
        });
        this.showTalk = false;
        this.getData();
      }
    },
    async getData() {
      const { data } = await connectRecord(this.queryData);
      if (data.code == 1) {
        this.tableData = data.data.data;
        this.total = data.data.total;
      }
    },
    talkFn(row) {
      this.maskItem = row;
      this.showTalk = true;
    },
  },
  mounted() {},
  async created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.getData();
    let statusArr = await this.$getCate.getCateFn(9);
    this.statusArr = statusArr.map((item) => {
      return { label: item.name, value: item.name };
    });
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>沟通记录（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.real_name"
                placeholder="请输入船员姓名"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.connect_remark"
                placeholder="请输入沟通备注"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.staff_name"
                placeholder="请输入沟通员工"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.connect_label"
                clearable
                @change="getData"
                placeholder="请选择沟通标签"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>

            <btn value="搜索" @ok="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="real_name"
          show-overflow-tooltip
          label="船员姓名"
        />
        <el-table-column
          prop="staff_name"
          show-overflow-tooltip
          label="沟通员工"
        >
          <template #default="{ row }">
            {{ row.staff_name }}
          </template>
        </el-table-column>
        <el-table-column
          width="150"
          prop="mobile"
          show-overflow-tooltip
          label="手机号"
        />
        <el-table-column
          prop="connect_remark"
          width="250"
          show-overflow-tooltip
          label="沟通备注"
        />
        <el-table-column
          prop="connect_label"
          show-overflow-tooltip
          label="沟通标签"
        />
        <el-table-column
          prop="create_time"
          show-overflow-tooltip
          width="200"
          label="沟通时间"
        />
        <el-table-column
          width="120"
          prop="last_connect_time"
          show-overflow-tooltip
          label="下次沟通提醒"
        />

        <el-table-column prop="Name" width="130" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="greenText ctrlText"
                @click="detailFn(row.biographical_notes_id)"
              >
                详情
              </div>
              <div class="blueText ctrlText" @click="talkFn(row)">再次沟通</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
    <el-dialog v-model="showTalk" title="新增船员沟通" width="600">
      <div class="dialogMaskCont">
        <talkForm
          @cancel="showTalk = false"
          @ok="comfirFn"
          :maskItem="maskItem"
        ></talkForm>
      </div>
    </el-dialog>
  </outMain>
</template>
<style scoped lang="less"></style>
